﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.ApplicationSettings;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Catalogo.Windows8.Common;
using Catalogo.Portable.ViewModel;
using Catalogo.Portable.ViewModel.Messages;

// The Basic Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234237

namespace Catalogo.Windows8.Views
{
    public sealed partial class FlyoutTexto : LayoutAwarePage
    {
        private TipoFlyoutTexto _TipoFlyoutTexto;

        public FlyoutTextoViewModel ViewModel
        {
            get
            {
                if (this.DefaultViewModel.ContainsKey("ViewModel"))
                {
                    return this.DefaultViewModel["ViewModel"] as FlyoutTextoViewModel;
                }
                return null;
            }
            set { this.DefaultViewModel["ViewModel"] = value; }
        }

        public FlyoutTexto(TipoFlyoutTexto tipoFlyoutTexto)
        {
            _TipoFlyoutTexto = tipoFlyoutTexto;

            this.InitializeComponent();
            Loaded += FlyoutTexto_Loaded;
        }

        async void FlyoutTexto_Loaded(object sender, RoutedEventArgs e)
        {
            ViewModel = new FlyoutTextoViewModel();
            await ViewModel.LoadAsync(_TipoFlyoutTexto);
        }

        private void CloseFlyout(object sender, RoutedEventArgs e)
        {
            if (this.Parent is Popup)
                (this.Parent as Popup).IsOpen = false;

            SettingsPane.Show();
        }
    }
}
